home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Finder / Fix Icon Picture next >
Encoding:
Text File  |  1999-03-04  |  2.1 KB  |  100 lines  |  [TEXT/ToyS]

  1. on open fsObjs
  2.     set n to the number of items of fsObjs
  3.     set pf to PrimeFactor(n)
  4.     
  5.     if (the number of items of pf) is not 2 then
  6.         -- Ask user for number vertical, since we can't figure it out
  7.         display dialog ("The number of icons (" & n & ") does not have exactly two prime factors." & return ¬
  8.             & return & "Please enter the number of lines of icons needed for the image.") ¬
  9.             default answer (n / (item 2 of pf)) ¬
  10.             buttons {"Cancel", "OK"} ¬
  11.             default button 2
  12.         
  13.         set v to n / (the text returned of the result)
  14.     else
  15.         display dialog ("How many lines of icons are needed?") ¬
  16.             buttons {item 1 of pf, item 2 of pf} ¬
  17.             default button 2
  18.         
  19.         set v to the button returned of the result
  20.     end if
  21.     
  22.     set fsObjs to SortFileList(fsObjs)
  23.     
  24.     set h to n / v
  25.     set x to 32
  26.     set y to 32
  27.     set i to 1
  28.     
  29.     repeat with fsObj in fsObjs
  30.         SetPosition(fsObj, x, y)
  31.         set i to i + 1
  32.         set x to x + 32
  33.         if (i > h) then
  34.             set y to y + 32
  35.             set x to 32
  36.             set i to 1
  37.         end if
  38.     end repeat
  39. end open
  40.  
  41.  
  42. on PrimeFactor(n)
  43.     set pf to {}
  44.     
  45.     repeat while n > 3
  46.         repeat with i from 2 to 111
  47.             if (n mod i) is 0 then
  48.                 set n to n / i
  49.                 set pf to pf & {i}
  50.                 exit repeat
  51.             end if
  52.         end repeat
  53.     end repeat
  54.     
  55.     return pf
  56. end PrimeFactor
  57.  
  58.  
  59. on SortFileList(fsObjs)
  60.     -- Insertion sort
  61.     set tList to {}
  62.     set fList to {}
  63.     set cnt to 0
  64.     repeat with fsObj in fsObjs
  65.         set fname to catalog name of (basic info for fsObj)
  66.         set n to 0
  67.         repeat with t in tList
  68.             if (fname > t) then
  69.                 set n to n + 1
  70.             else
  71.                 exit repeat
  72.             end if
  73.         end repeat
  74.         
  75.         if (n is 0) then
  76.             set tList to {fname} & tList
  77.             set fList to {fsObj} & fList
  78.         else if (n is cnt) then
  79.             set tList to tList & {fname}
  80.             set fList to fList & {fsObj}
  81.         else
  82.             set tList to (items 1 through n of tList) & fname & (items (n + 1) through -1 of tList)
  83.             set fList to (items 1 through n of fList) & fsObj & (items (n + 1) through -1 of fList)
  84.         end if
  85.         set cnt to cnt + 1
  86.     end repeat
  87.     
  88.     return fList
  89. end SortFileList
  90.  
  91.  
  92. on SetPosition(fsObj, x, y)
  93.     -- Set the position of a file's icon in a folder to x,y
  94.     try
  95.         tell application "Finder" to set the position of fsObj to {x, y}
  96.     on error
  97.         beep
  98.     end try
  99. end SetPosition
  100.